package com.zlict.admin.controller;

import com.zlict.admin.domain.Project;
import com.zlict.admin.domain.ProjectAndProjectApproval;
import com.zlict.admin.service.IProjectService;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.enums.BusinessType;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目基本信息Controller
 * 
 * @author dzw
 */
@RestController
@RequestMapping("/admin/project")
public class ProjectController extends BaseController
{
    @Autowired
    private IProjectService projectService;

    /**
     * 查询项目基本信息列表
     */
//    @PreAuthorize("@ss.hasPermi('admin:project:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(@Param("projectName") String projectName,@Param("type") String type)
//    {
//        //todo 需要改
//
//        startPage();
//        List<ProjectAndProjectApproval> list = projectService.selectProjectList(projectName,type);
//        return getDataTable(list);
//    }
    //@PreAuthorize("@ss.hasPermi('admin:project:list')")
    @GetMapping("/list")
    public AjaxResult list(@Param("projectName") String projectName,@Param("type") String type)
    {
        //todo 需要改

//        startPage();
        List<ProjectAndProjectApproval> list = projectService.selectProjectList(projectName,type);
        return success(list);
    }


    /**
     * 获取项目基本信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('admin:project:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectService.selectProjectById(id));
    }

    /**
     * 新增项目基本信息
     */
    //@PreAuthorize("@ss.hasPermi('admin:project:add')")
    @Log(title = "项目基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Project project)
    {
        return success(projectService.insertProject(project));
    }

    /**
     * 修改项目基本信息
     */
    //@PreAuthorize("@ss.hasPermi('admin:project:edit')")
    @Log(title = "项目基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Project project)
    {
        return toAjax(projectService.updateProject(project));
    }

    /**
     * 修改项目状态
     */
    //@PreAuthorize("@ss.hasPermi('admin:project:edit')")
    @Log(title = "项目基本信息", businessType = BusinessType.UPDATE)
    @PutMapping("/editStatus")
    public AjaxResult editStatus(@RequestBody ProjectAndProjectApproval project)
    {

        return toAjax(projectService.updateProjectStatus(project));
    }

    /**
     * 删除项目基本信息
     */
    //@PreAuthorize("@ss.hasPermi('admin:project:remove')")
    @Log(title = "项目基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectService.deleteProjectByIds(ids));
    }



}
